<script setup lang="ts">
  import { onMounted, ref } from 'vue';
  import { BasicTree, TreeItem } from '@/components/Tree';
  import { MessageSource } from '@/api/resource/resourceAllApi';

  const { leftTree } = MessageSource();

  defineOptions({ name: 'CloudTree' });
  const emit = defineEmits(['select']);
  const treeData = ref<TreeItem[]>([]);

  async function fetch() {
    treeData.value = (await leftTree()) as unknown as TreeItem[];
  }

  function handleSelect(keys) {
    emit('select', keys[0]);
  }

  onMounted(() => {
    fetch();
  });
</script>

<template>
  <div class="m-4 mr-0 overflow-hidden bg-white">
    <BasicTree
      title="云资源分类"
      toolbar
      search
      treeWrapperClassName="h-[calc(100%-35px)] overflow-auto"
      :clickRowToExpand="false"
      :treeData="treeData"
      :fieldNames="{ key: 'dictCode', title: 'dictName' }"
      @select="handleSelect"
    />
  </div>
</template>
